<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">

<body>

<div th:fragment="nav">
    <nav class="navbar navbar-expand-lg navbar-light bg-light mb-5 text-light">
        <dvi class="container">
            <a class="navbar-brand" href="/">Demo</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                    aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="/">主页 <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <form class="form-inline my-2 my-lg-0" action="/" method="get">
                            <input class="form-control mr-sm-2" type="search" name="search" placeholder="请输入关键字" aria-label="Search">
                            <button class="btn btn-success my-2 my-sm-0" type="submit">搜索</button>
                        </form>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item" th:if="${session.user == null}">
                        <a class="nav-link"
                           href="https://github.com/login/oauth/authorize?client_id=cee8aa31037deae13bc8&redirect_uri=http://127.0.0.1:8080/callback&scope=user&state=1">登录</a>
                    </li>
                    <li class="nav-item" th:if="${session.user != null}">
                        <a href="/publish" class="nav-link">提问</a>
                    </li>
                    <li class="nav-item" th:if="${session.user != null}">
                        <a href="/profile/replies" class="nav-link">通知
                            <span class="badge badge-danger badge-pill float-right ml-1" th:if="${session.unreadCount != 0}" th:text="${session.unreadCount}"></span>
                        </a>
                    </li>
                    <li class="nav-item dropdown" th:if="${session.user != null}">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <span th:text="${session.user.getName()}"></span>
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href="/profile/questions">我的提问</a>
                            <a class="dropdown-item" href="/logout">退出登录</a>
                        </div>
                    </li>
                </ul>
            </div>
        </dvi>
    </nav>
</div>

</body>

</html>